import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.Map;

public class TestActiviti2 {
    ApplicationContext ioc=new ClassPathXmlApplicationContext("spring/spring-*.xml");
    ProcessEngine processEngine=(ProcessEngine)ioc.getBean("processEngine");
    //部署流程定义
    @Test
    public void test01(){
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment().addClasspathResource("Myprocess4.bpmn").deploy();
        System.out.println("deploy="+deploy);
    }
    //启动流程实例
    //流程变量
    //如果存在流程变量，那么必须要给流程实例赋值，否者，启动流程实例会报错
    @Test
    public  void test02(){
        ProcessDefinition processDefinition = processEngine.getRepositoryService().createProcessDefinitionQuery().latestVersion().singleResult();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //流程变量赋值
        Map<String, Object> map = new HashMap<>();
        map.put("tl","zhangsan");
        map.put("pm","lisi");
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(),map);
        System.out.println("processInstance="+processInstance);


    }

}
